package algorithms.que13;

/**
 * @功能
 * @创建时间 2020/7/2
 */
public class ParenthesesStack {
    private Node first;
    private int N;
    private class Node {
         String item;
         Node next;
    }
    public void push(String s){
        Node oldfirst = first;
        first = new Node();
        first.item=s;
        first.next=oldfirst;
        N++;
    }
    public String peek(){
        return first.item;
    }
    public boolean Peidui(String p){

        char[] w = p.toCharArray();
        for(char i:w){
            if(first==null)
                push(String.valueOf(i));
            else
            if((first.item.equals("(")&&String.valueOf(i).equals(")"))||
                    (first.item.equals("[")&&String.valueOf(i).equals("]"))||
                    (first.item.equals("{")&&String.valueOf(i).equals("}"))//||
             /*       (first.item.equals(")")&&String.valueOf(i).equals("("))||
                    (first.item.equals("]")&&String.valueOf(i).equals("["))||
                    (first.item.equals("}")&&String.valueOf(i).equals("{"))*/
            )
                pop();
            else
            push(String.valueOf(i));
        }
        return first==null;
    }
    public void pop(){
        first=first.next;
        N--;
    }
}
class Client{
    public static void main(String[] args) {
        ParenthesesStack p = new ParenthesesStack();
        System.out.println(p.Peidui("[{]}"));
    }
}